package com.cqut.ktpspring.controller;

import com.cqut.ktpspring.pojo.Result;
import com.cqut.ktpspring.pojo.Work;
import com.cqut.ktpspring.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
public class WorkController {
    @Autowired
    private WorkService workService;

    @GetMapping("/workList")
    public Result selectUsers(@RequestParam String cno) {
        log.info("查询某个课程的作业{}", cno);
        System.out.println(workService.selectWorks(cno));
        return Result.success(workService.selectWorks(cno));
    }

    @PostMapping("/insertWork")
    public Result insertTask(@RequestBody Work work) {
        log.info("新增作业{}", work);
        workService.insertWork(work);
        return Result.success();
    }

    @PutMapping("/updateWork")
    public Result updateTask(@RequestBody Work work) {
        log.info("更新作业{}", work);
        workService.updateWork(work);
        return Result.success();
    }

    @DeleteMapping("/deleteWork")
    public Result deleteTask(@RequestParam String id) {
        log.info("删除作业{}", id);
        workService.deleteWork(id);
        return Result.success();
    }
}
